package com.linanqing.aidldemo.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;

import com.linanqing.javademo.IMyAidlInterface;

public class TestService extends Service {
    public TestService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
       // throw new UnsupportedOperationException("Not yet implemented");
        return new IMyAidlInterface.Stub() {
            @Override
            public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

            }

            @Override
            public void setData(String data) throws RemoteException {
                TestService.this.data  = data;
                //System.out.println(data);
            }
        };
    }

    private String data = "测试数据";
    private boolean running = true;

    @Override
    public void onCreate() {
        super.onCreate();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (running){
                    System.out.println(data);
                    SystemClock.sleep(1000);
                }


            }
        }).start();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        running = false;
    }
}